package com.situ.lession1226.api;

import com.situ.lession1226.model.Professional;
import com.situ.lession1226.service.ProfessionalService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

//对每个电影下面的评论进行展示和增加
@RestController
@RequestMapping(value = "/api/v1/professional", produces = "application/json;charset=utf-8")
public class ProfessionalApi {
    private ProfessionalService professionalService;

    public ProfessionalApi(ProfessionalService professionalService) {
        this.professionalService = professionalService;
    }

    @GetMapping("/get")
    public Map<String,Object> get(){
        List <Professional> professional=professionalService.findAllBy();

        if (professional == null) {
            return Map.of("success", false);
        } else {
            return Map.of("success",true,"professional",professional);
        }

    }
    @PostMapping("/post")
    public Map<String, Object> post(Professional professional){
        boolean success = professionalService.save(professional);
        return Map.of("success", success);
    }
}
